package com.example.a313ldy.yuejian_17.Fragment.IndexFragment.MasterFragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.RadioGroup;

import com.example.a313ldy.yuejian_17.R;

/**
 * Created by LDY on 2017/11/2.
 */

public class ChoicenessFragment extends Fragment {
    private RadioGroup radioGroup;
    private FragmentManager manager;
    private FragmentTransaction transaction;
    private Fragment mTab01;
    private Fragment mTab02;



    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        radioGroup = (RadioGroup) view.findViewById(R.id.main_tab_RadioGroup);
        manager = getChildFragmentManager();
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.master_course:
                        mTab01 = new MasterCrouseFragment();
                        replace(mTab01);
                        break;
                    case R.id.master_response:
                        mTab02 = new MasterResponseFragment();
                        replace(mTab02);
                        break;
                }

            }
        });

        radioGroup.check(R.id.index_activity);


    }

    private void  replace(Fragment fragment){

        transaction=manager.beginTransaction();
        transaction.replace(R.id.id_content,fragment);
        transaction.commit();


    }


    public ChoicenessFragment() {
    }
}
